import androidx.fragment.app.Fragment

//package com.oy.topline.fragment
//
//import android.os.*
//import android.view.*
//import androidx.fragment.app.Fragment
//import androidx.recyclerview.widget.LinearLayoutManager
//import com.itheima.PullToRefreshView
//import com.oy.topline.R
//import com.oy.topline.adapter.VideoListAdapter
//import com.oy.topline.bean.VideoBean
//import com.oy.topline.utils.*
//import com.oy.topline.view.WrapRecyclerView
//import com.squareup.okhttp.Callback
//import com.squareup.okhttp.OkHttpClient
//import com.squareup.okhttp.Request
//import com.squareup.okhttp.Response
//import java.io.IOException
//
class VideoFragment : Fragment() {
//    private var mPullToRefreshView: PullToRefreshView? = null
//    private var recycleView: WrapRecyclerView? = null
//    private var mHandler //事件捕获
//            : MHandler? = null
//    private var adapter: VideoListAdapter? = null
//    override fun onCreateView(
//        inflater: LayoutInflater, container: ViewGroup?,
//        savedInstanceState: Bundle?
//    ): View? {
//        mHandler = MHandler()
//        initData()
//        return initView(inflater, container)
//    }
//
//    private fun initView(inflater: LayoutInflater, container: ViewGroup?): View {
//        val view = inflater.inflate(R.layout.fragment_video, container, false)
//        recycleView = view.findViewById<View>(R.id.recycler_view) as WrapRecyclerView
//        recycleView!!.layoutManager = LinearLayoutManager(context)
//        adapter = VideoListAdapter(activity)
//        recycleView!!.setAdapter(adapter)
//        mPullToRefreshView = view.findViewById<View>(R.id.pull_to_refresh) as PullToRefreshView
//        mPullToRefreshView!!.setOnRefreshListener {
//            mPullToRefreshView!!.postDelayed({
//                mPullToRefreshView!!.setRefreshing(false)
//                initData()
//            }, REFRESH_DELAY.toLong())
//        }
//        return view
//    }
//
//    private fun initData() {
//        val okHttpClient = OkHttpClient()
//        val request = Request.Builder().url(Constant.WEB_SITE + Constant.REQUEST_VIDEO_URL).build()
//        val call = okHttpClient.newCall(request)
//        //开启异步线程访问网络
//        call.enqueue(object : Callback {
//            @Throws(IOException::class)
//            override fun onResponse(response: Response) {
//                val res = response.body().string()
//                val msg = Message()
//                msg.what = MSG_VIDEO_OK
//                msg.obj = res
//                mHandler!!.sendMessage(msg)
//            }
//
//            override fun onFailure(arg0: Request, arg1: IOException) {}
//        })
//    }
//
//    /**
//     * 事件捕获
//     */
//    internal inner class MHandler : Handler() {
//        override fun dispatchMessage(msg: Message) {
//            super.dispatchMessage(msg)
//            when (msg.what) {
//                MSG_VIDEO_OK -> if (msg.obj != null) {
//                    val vlResult = msg.obj as String
//                    //使用Gson解析数据
//                    val videoList: List<VideoBean> =
//                        JsonParse.Companion.getInstance().getVideoList(vlResult)
//                    adapter!!.setData(videoList)
//                }
//            }
//        }
//    }
//
//    companion object {
//        const val REFRESH_DELAY = 1000
//        const val MSG_VIDEO_OK = 1 //获取数据
//    }
}